
***inputs:
* $OrigData\PrecipISD`y'.csv y=2013:2018


*** outputs:
* $Data\PrecipISD`y'.dta y=2013:2018


forval y = 2013(1)2018 {
	clear
	
	insheet using $OrigData/precipISD`y'.csv, 

	drop v1	
	
	rename wban WBAN
	rename usaf USAF
	
	
	rename date date_num
	tostring date_num, gen(date_str) usedisplayformat 

	gen date = date(date_str, "YMD")
	format date %td

	tostring time , gen(time_str) 

	gen hour_str = substr(time_str, -4,2)
	replace hour_str = substr(time_str, -3,1) if hour_str==""
	replace hour_str = "0" if length(time_str) <=2 
	destring hour_str, gen(hour)
	
	gen min_str = substr(time_str,-2,2)
	replace min_str = substr(time_str,-1,1) if length(time_str) <2
	
	destring min_str, gen(min)
	
	
	gen hour_round = (hour+1)*(min>30) + hour*(min<=30)
	replace hour_round = 0 if hour_round ==24
	
	drop time hour_str min_str min hour date_num
	
	rename hour_round hour
	
	gen precip_length = aa3_period_quantity_hrs
	replace precip_length = "0" if precip_length == "NA"
	
	destring precip_length, replace
	
	gen precip_measurement = aa3_depth
	replace precip_measurement = "0" if precip_measurement == "NA"
	
	destring precip_measurement, replace
	
	replace precip_measurement = . if precip_measurement ==9999
	
save $Data/PrecipISD`y'.dta, replace

}



